;;;
;;; Overall parent class
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (thing n)
	(let ((name n)										;Thing's name
		  (type 'thing))								;Identifier
			
	(define setName
		(lambda (newN)
			(begin (set! name newN) newN)
		)
	)
	(define this
		(lambda (msg)
			(cond ((eq? msg 'getType) type)				;Return thing's type
				  ((eq? msg 'getName) name)				;Return thing's name
				  ((eq? msg 'setName) setName)			;Change thing's name
				  (else (begin (display "I don't understand") nil))
			)
		)
	)
	this)
)


(define (associate label pairs)
  (cond ((null? pairs) nil)
	((eq? label (caar pairs)) (car pairs))
	(else (associate label (cdr pairs)))))

(define (forall set f)
  (cond ((null? set) nil)
	(else (f (car set))
	      (forall (cdr set) f))))

(define (filter set f)
  (cond ((null? set) '())
	((f (car set))
	 (cons (car set) (filter (cdr set) f)))
	(else (filter (cdr set) f))))

(define (delete o possessions)
  (let ((answer '()))
    (forall possessions
	    (lambda (elem)
	      (if (not (eq? elem o))
		  (set! answer (cons elem answer)))))
    answer))

(define nil '())

(define room1 (room 'room1))
(define room2 (room 'room2))
(define room3 (room 'room3))
((room1 'addNeighbor) 'north room2)
((room1 'addNeighbor) 'south room3)
((room2 'addNeighbor) 'north room3)
((room2 'addNeighbor) 'south room1)
((room3 'addNeighbor) 'north room1)
((room3 'addNeighbor) 'south room2)

(define sword (weapon 'shortsword))
((room2 'addObject) sword)

(define player1 (player 'Graboth room1))

(define input-prompt (string-append (symbol->string(player1 'getName)) " : "))

(define (startgame) (begin (clear) (game-loop)))

(define (game-loop)
	(prompt-for-input input-prompt)
	(let ((input (read)))
	(begin (clear)
		(if (null? (cdr input))
			((player1 (car input)))
			((player1 (car input)) (car (cdr input)))
		)
	)
  (game-loop))
)
(define (prompt-for-input string)
  (newline) (newline) (display string))

(define (print-message strlst)
	(define (loop lst str)
		(if (null? lst)
			(begin
				(newline)
				(display str)
			)
			(let ((e (car lst))
				  (tmpStr str))
				(begin
				(cond ((string? e) (set! tmpStr (string-append str e)))
					  ((symbol? e) (set! tmpStr (string-append str (symbol->string e))))
					  ((list? e)   (set! tmpStr (string-append str (list->string e))))
					  (else nil))
				(loop (cdr lst) tmpStr))
			)
		)
	)
	(if (pair? strlst)
		(loop strlst "")
			(begin
				(newline)
				(display strlst)
			)
	)
	
)

;(define (car-string string)
;	(string-trim (string-trim-right string (char-set #\space)))
;)

;(define (cdr-string string)
;	(string-trim (string-trim-left string (char-set #\space)))
;)
